package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import properties.Constants;
import properties.DefaultProperties;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import java.awt.Font;

/**
 * This class provides the window for the application information.
 * @author Kevin Wagner
 * @version 1.0
 */
public class InfoWindow extends JFrame implements ActionListener{

	private static final long serialVersionUID = 7383379889305231382L;
	private JPanel contentPane;
	private JButton btnClose;

	/**
	 * Create the frame.
	 * @param props properties
	 */
	public InfoWindow(DefaultProperties props) {
		super(props.getLocalizedText("about"));
		setAlwaysOnTop(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(50, 50, 300, 300);
		this.setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		btnClose = new JButton(props.getLocalizedText("close"));
		btnClose.addActionListener(this);
		
		JLabel nameL = new JLabel(props.getLocalizedText("ufr"));
		nameL.setFont(new Font("Tahoma", Font.BOLD, 14));
		nameL.setHorizontalAlignment(SwingConstants.CENTER);
		
		JLabel versionL = new JLabel(props.getLocalizedText("version").replaceAll("%version%", Constants.VERSION));
		
		JLabel authorL = new JLabel(props.getLocalizedText("author").replaceAll("%author%", Constants.AUTHOR));
		
		JLabel copyrightL = new JLabel(props.getLocalizedText("copyright").replaceAll("%copyright%", Constants.AUTHOR+" "+Constants.YEAR));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(353, Short.MAX_VALUE)
					.addComponent(btnClose))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addComponent(nameL, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
					.addContainerGap())
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(versionL, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(authorL)
					.addContainerGap(384, Short.MAX_VALUE))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(copyrightL)
					.addContainerGap(384, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addComponent(nameL, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(versionL)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(authorL)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(copyrightL)
					.addPreferredGap(ComponentPlacement.RELATED, 168, Short.MAX_VALUE)
					.addComponent(btnClose))
		);
		contentPane.setLayout(gl_contentPane);
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent ev) {
		if(ev.getSource()==btnClose){
			this.dispose();
		}
		
	}
}
